package com.ruoyi.lottery.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.lottery.domain.TbLottery;
import com.ruoyi.lottery.service.ITbLotteryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 抽奖Controller
 * 
 * @author LiuWeiChen
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/lottery")
public class TbLotteryController extends BaseController
{
    @Autowired
    private ITbLotteryService tbLotteryService;

    /**
     * 查询抽奖列表
     */
    @RequiresPermissions("lottery:lottery:list")
    @GetMapping("/list")
    public TableDataInfo list(TbLottery tbLottery)
    {
        startPage();
        List<TbLottery> list = tbLotteryService.selectTbLotteryList(tbLottery);
        return getDataTable(list);
    }

    /**
     * 导出抽奖列表
     */
    @RequiresPermissions("lottery:lottery:export")
    @Log(title = "抽奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLottery tbLottery)
    {
        List<TbLottery> list = tbLotteryService.selectTbLotteryList(tbLottery);
        ExcelUtil<TbLottery> util = new ExcelUtil<TbLottery>(TbLottery.class);
        util.exportExcel(response, list, "抽奖数据");
    }

    /**
     * 获取抽奖详细信息
     */
    @RequiresPermissions("lottery:lottery:query")
    @GetMapping(value = "/{lotteryId}")
    public AjaxResult getInfo(@PathVariable("lotteryId") Long lotteryId)
    {
        return success(tbLotteryService.selectTbLotteryByLotteryId(lotteryId));
    }

    /**
     * 新增抽奖
     */
    @RequiresPermissions("lottery:lottery:add")
    @Log(title = "抽奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLottery tbLottery)
    {
        return toAjax(tbLotteryService.insertTbLottery(tbLottery));
    }

    /**
     * 修改抽奖
     */
    @RequiresPermissions("lottery:lottery:edit")
    @Log(title = "抽奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLottery tbLottery)
    {
        return toAjax(tbLotteryService.updateTbLottery(tbLottery));
    }

    /**
     * 删除抽奖
     */
    @RequiresPermissions("lottery:lottery:remove")
    @Log(title = "抽奖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lotteryIds}")
    public AjaxResult remove(@PathVariable Long[] lotteryIds)
    {
        return toAjax(tbLotteryService.deleteTbLotteryByLotteryIds(lotteryIds));
    }
}
